<?php
require_once MOD_ROOT.'member/member.func.php';

// 加载会员类
/*require MOD_ROOT.'member/includes/member.class.php';
$member = new member();*/


include 'forum.class.php';
$forum = new forum();

// 获取所有论坛版块的数组集合
$data = $db->select("select * from ".DB_PRE."forum");
$FORUM = '';
foreach($data as $k=>$v){
	$FORUM[$v['fid']] = $v;
}
unset($data);

// 获取上一页
if(!$forward) $forward = HTTP_REFERER;

	switch($action)
	{
		case 'thread_list':
			
			
			$forumdata = $db->get_one("select * from ".DB_PRE."forum where fid = $fid");
			//dump($forumdata);
			
			$threads = $forum->thread_listinfo("`fid`=$fid", '`tid` DESC', $page, 5);
			//dump($threads);
			//$threads = $db->select("select * from ".DB_PRE."forum_thread where fid = {$fid}");
			include	template('forum_thread_list.html','forum');
			
		break;
		
		case 'thread_view':
		
			$data = $db->get_one("select * from ".DB_PRE."forum_thread t, ".DB_PRE."forum_post p where t.tid = p.tid and t.tid = $tid and p.first = 1");
			//dump($data);
			
			$comments = $db->select("select * from ".DB_PRE."forum_post where tid = $tid and first <> 1");
			//dump($comments);
			
			include template('forum_thread_view.html','forum');
		break;
		
		case 'thread_new':
			
			if($dosubmit){
				
				$thread = array('fid'=>$fid,
								'subject' => $title,
								'author'=> $_username,
								'authorid'=>$_userid
								);
				
				$db->insert(DB_PRE.'forum_thread',$thread);
				$tid = $db->insert_id();
				
				$post = array(
								'tid'=>$tid,
								'fid'=>$fid,
								'first'=>1, // first为1的是帖子，为0的是回复
								'subject'=>$title,
								'message'=>$message,
								'author'=> $_username,
								'authorid'=>$_userid
				        		);
				$db->insert(DB_PRE.'forum_post',$post);
				showmessage('发布成功',"?module=$module&action=thread_view&tid=$tid&fid=$fid&rand=".rand(0,100));
				
			}
			else{
				require 'form.class.php';
				include template('forum_thread_new.html','forum');
			}
		break;
		
		// 发表回复
		case 'comment':
			if($dosubmit){
				$db->insert(DB_PRE.'forum_post',$post);
				
				extract($post);
				showmessage('回复成功',"?module=$module&action=thread_view&fid=$fid&tid=$tid&rand=".rand(0,100));
				
			}
		break;
		
		default:
		
			$forums = $db->select("select * from ".DB_PRE."forum");
			include	template('forum_index.html','forum');
		break;
	}
?>